<%-- 
    Document   : index
    Created on : 04.02.2012, 22:54:04
    Author     : Paul Wagner
--%>

<%@page import="java.io.IOException"%>
<%@page import="java.io.ObjectInputStream"%>
<%@page import="java.io.ObjectOutputStream"%>
<%@page import="java.net.Socket"%>
<%@page import="java.net.InetAddress"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
            String jsonText = request.getParameter("json");

            //
            // Create a connection to the server socket on the server application
            //
            InetAddress host = InetAddress.getLocalHost();
            String s = "";
            String result = "";
            Socket socket = null;
            try {
                socket = new Socket(host.getHostName(), 1337);
            } catch (IOException e) {
                s = "Failed to connect to Server!";
            }

            if (!s.isEmpty() || socket == null) {
                response.sendError(418, s);
            } else {
                //
                // Send a data
                //
                ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                oos.writeObject(jsonText);

                //
                // Read and display the response message sent by server application
                //
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                result = (String) ois.readObject();
            }
%>
<%= result%>

